package lockSupportTest;

/**
 * @program: javase
 * @description: 测试notify()随机唤醒正在等待的进程
 * @author: luolidong
 * @create: 2021-06-23 20:56
 * @version: 1.0
 */
public class WaitNotifyTest {
    private static final Object lock=new Object();
    public static void main(String[] args) {
        new Thread(()->{
            synchronized (lock){
                System.out.println("a");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("a唤醒");
            }
        }).start();
        new Thread(()->{
            synchronized (lock){
                System.out.println("b");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("b唤醒");
            }
        }).start();
        new Thread(()->{
            synchronized (lock){
                System.out.println("c");
                lock.notify();
//                System.out.println("a唤醒");
            }
        }).start();
    }
}
